#include<iostream>
#include<string.h>
#include<stack> 
using namespace std;
int main()
{
	stack<char>kuohao;
	char a[10005];
	int n,i,j,judge;
	scanf("%d",&n);getchar();
	while(n--)
	{
		judge=1;
		cin.getline(a,10005);
		for(i=0;i<strlen(a);i++)
		{
			if(a[i]=='['||a[i]=='(')
				kuohao.push(a[i]);
			else
			{
				if(kuohao.empty())
				{
					judge=0;
					break;
				}
				else if( (kuohao.top()=='['&&a[i]==']') || (kuohao.top()=='('&&a[i]==')'))
					kuohao.pop();
				else
				{
					judge=0;
					break;
				}
			}
		}
		if(judge)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}
